home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / MorphOS / Epic4_mos / share / epic / script / epic-crypt-gpg < prev    next >
Encoding:
Text File  |  2002-10-28  |  831 b   |  33 lines

  1. #!/bin/bash
  2. #
  3. # This is a simplistic encryption demonstrating the principles
  4. # of the protocol, while being quite usable.
  5. #
  6. # the first input line contains words, the first of which is the key,
  7. # and additional arguments, which aren't used right now, so they are
  8. # discarded.
  9. #
  10. # When the end of the line is reached, the rest of the input is to be
  11. # read as binary input of the plaintext or cyphertext in _binary_ mode.
  12. # What this means for plaintext is that the newline terminator won't
  13. # be present.
  14.  
  15. function encrypt {
  16.     ( echo "$KEY" ; cat ) | gpg -c -z 9 --batch --passphrase-fd 0
  17. }
  18.  
  19. function decrypt {
  20.     ( echo "$KEY" ; cat ) | gpg --batch --passphrase-fd 0
  21. }
  22.  
  23. proto="$1"
  24. shift 1
  25.  
  26. read KEY TRASH
  27.  
  28. case "$proto" in
  29. encrypt) encrypt "$@" ;;
  30. decrypt) decrypt "$@" ;;
  31. *)    echo `basename $0` "{encrypt|decrypt} < text" 1>&2 ;;
  32. esac
  33.